const mysql = require("mysql");

let pool = mysql.createPool({
    host: '127.0.0.11',
    user: 'root',
    password: 'root',
    database: 'shop360',
    port: 3306,
})

const exec = (sql,pramas) =>{
    return new Promise((resolve,reject) =>{
        pool.getConnection((err,conn) =>{
            if(err){
                console.log("数据库连接失败" + err);
                reject(err);
            }
            conn.query(sql,pramas,(err,result) =>{
                if(err){
                    console.log("sql语句执行失败" + err);
                    reject(err);
                }
                resolve(result);
                conn.release()
            })
        })
    })
}

module.exports = {
    exec
}